﻿package {
	import flash.display.Shape;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import idv.cjcat.pyronova.nodes.Draw;
	import idv.cjcat.pyronova.nodes.FillRect;
	import idv.cjcat.pyronova.nodes.Group;
	import idv.cjcat.pyronova.nodes.Node;
	import idv.cjcat.pyronova.utils.PyroMath;
	
	public class Main extends PyronovaExample {
		
		private var group:Group;
		
		public function Main():void {
			super("Group");
		}
		
		override protected function buildPreprocessor():Node {
			//clean buffer
			return new FillRect(view.bitmapData().rect, 0x00000000);
		}
		
		override protected function buildRoot():Node {
			var square:Shape = new Shape();
			square.graphics.lineStyle(2, 0x505050);
			square.graphics.drawRect(0, 0, 10, 10);
			
			group = new Group();
			group.position.set(160, 100);
			
			//draw square
			var count:int = 12;
			for (var i:int = 0; i < count; ++i) {
				var theta:Number = PyroMath.TWO_PI * i / count;
				var draw:Node = new Draw(square);
				draw.center.set(5, 5);
				draw.position.set(70 * Math.cos(theta), 70 * Math.sin(theta));
				draw.rotation = theta * PyroMath.RADIAN_TO_DEGREE;
				group.add(draw);
			}
			
			return group;
		}
		
		override protected function mainLoop():void {
			group.rotation += 0.5;
		}
	}
}